
var app = getApp()
Page({
  data: {
    addressList:[]
  },

  selectTap: function (e) {
    var id = e.currentTarget.dataset.id;
    wx.request({
       url: '#',
      data: {
      },
      success: (res) =>{
        wx.navigateBack({})
      }
    })
  },

  addAddess : function () {
    wx.navigateTo({
      url:"/pages/address_add/index"
    })
  },
  
  editAddess: function (e) {
    wx.navigateTo({
      url: "/pages/address_add/index?id=" + e.currentTarget.dataset.id
    })
  },
  
  onLoad: function () {
    console.log('onLoad')

   
  },
  onShow : function () {
    this.initShippingAddress();
  },
  initShippingAddress: function () {
    var that = this;
    wx.request({
      url: app.globalData.apiUrl+'/api/user/selectAddress',
      data: {openid:app.globalData.openid},
      success: (res) =>{
        that.setData({
            addressList:res.data
          });
        // if (res.data.code == 0) {
        //   that.setData({
        //     addressList:res.data.data
        //   });
        // } else if (res.data.code == 700){
        //   that.setData({
        //     addressList: null
        //   });
        // }
      }
    })
  },
  selectTap:function(tap){
    console.log(tap)
      var that = this;
      wx.request({
        url: app.globalData.apiUrl+'/api/user/selectTap',
        data: {id: tap.currentTarget.dataset.id},
        method: 'GET',
        dataType: 'json',
        responseType: 'text',
        success: function(res) {
          console.log(res)
          wx.request({
            url: app.globalData.apiUrl + '/api/user/selectAddress',
            data: { openid: app.globalData.openid },
            success: (res) => {
              that.setData({
                addressList: res.data
              });
              
            }
          })
        },
        fail: function(res) {},
        complete: function(res) {},
      })
  }
  

})
